package cn.hjh.dao;

import cn.hjh.pojo.Dept;

import java.util.List;


public class DeptDao extends BaseDao {
	public List<Dept> findByProjection_3() {
		return this.currentSession().createQuery("select new Dept(dname, loc) from Dept").list();
	}
	
	public List<Object[]> findByProjection_2() {
		return this.currentSession().createQuery("select dname, loc from Dept").list();
	}
	
	public List<String> findByProjection() {
		return this.currentSession().createQuery("select dname from Dept").list();
	}

	//按参数绑定
	public List<Dept> findDeptByName(String deptName) {
		return this.currentSession().createQuery("from Dept where dname = ?")
				.setString(0, deptName) // 位置从0开始
				.list();
	}

	//按参数名称绑定
	public List<Dept> findDeptByName_2(String deptName) {
		return this.currentSession().createQuery("from Dept where dname = :name")
				.setString("name", deptName) // 位置从0开始
				.list();
	}
	
	public List<Dept> findDeptByName_3(String deptName, String loc) {
		return this.currentSession().createQuery("from Dept where loc = ? and dname = ?")
				.setString(1, deptName) // 位置从0开始
				.setString(0, loc)
				.list();
	}
	
	public List<Dept> findDeptByName_4(String deptName, String loc) {
		return this.currentSession().createQuery("from Dept where loc = :loc and dname = :name")
				.setString("name", deptName) // 位置从0开始
				.setString("loc", loc)
				.list();
	}
}
